<template>
  <el-card class="course-card" @click="goToDetail">
    <div class="course-image">
      <img :src="require(`@/assets/${course.courseCover}`)" alt="课程封面">
      <div class="course-tag" v-if="course.tag">{{ course.tag }}</div>
    </div>
    <div class="course-info">
      <h3 class="course-title">{{ course.courseName }}</h3>
      <div class="course-teacher">
        <img :src="require(`@/assets/${course.teacherAvatar}`)" alt="讲师头像" class="teacher-avatar">
        <span>{{ course.teacherName }} {{ course.teacherUniversity }}</span>
      </div>
      <div class="course-metrics">
        <span class="metric-item"><i class="el-icon-user"></i> {{ course.capacity }}人学习</span>
        <span class="metric-item"><i class="el-icon-time"></i> {{ course.semester }}</span>
      </div>
      <div class="course-credit">
        <span >{{ course.credit }}学分</span>
      </div>
    </div>
  </el-card>
</template>

<script>
export default {
  name: 'CourseCard',
  props: {
    course: {
      type: Object,
      required: true
    }
  },
  methods: {
    goToDetail() {
      // 将id改为recordId以匹配API参数命名
      this.$router.push(`/course/detail/${this.course.recordId}`)
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
.course-card {
  height: 100%;
  display: flex;
  margin-bottom: 20px;
  flex-direction: column;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  cursor: pointer;
  
  &:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
  }
  
  .course-image {
    position: relative;
    height: 160px;
    overflow: hidden;
    
    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      transition: transform 0.5s ease;
    }
    
    &:hover img {
      transform: scale(1.05);
    }
    
    .course-tag {
      position: absolute;
      top: 10px;
      left: 10px;
      background-color: #ff7a45;
      color: white;
      padding: 2px 8px;
      border-radius: 4px;
      font-size: 12px;
    }
  }
  
  .course-info {
    padding: 15px;
    flex: 1;
    display: flex;
    flex-direction: column;
    
    .course-title {
      font-size: 16px;
      margin-bottom: 10px;
      color: #333;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      overflow: hidden;
      height: 40px;
    }
    
    .course-teacher {
      display: flex;
      align-items: center;
      margin-bottom: 10px;
      
      .teacher-avatar {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        margin-right: 5px;
      }
      
      span {
        font-size: 13px;
        color: #666;
      }
    }
    
    .course-metrics {
      display: flex;
      justify-content: space-between;
      margin-bottom: 10px;
      font-size: 12px;
      
      .metric-item {
        color: #999;
        display: flex;
        align-items: center;
        
        i {
          font-size: 12px;
          margin-right: 4px;
        }
      }
    }
    
    .course-credit {
      margin-top: auto;
      font-size: 18px;
      font-weight: bold;
      color: #ff4d4f;
    }
  }
}
</style>